$(document).ready(function () {
    var likes = $(".like");
    $.each(likes,function (index, value) {
        if (value.getAttribute('data-status')==="1"){
            value.getElementsByTagName("img")[0].setAttribute('src','/static/movie/images/like-on.png')
        }
    });
    // 星星打分
    $(".rating-score-star").raty({
        readOnly: function () {
            return $(this).attr("data-readOnly")
        },
        path: function () {
            return $(this).attr('data-path')
        },
        score: function () {
            return ($(this).attr('data-score')) / 2
        }
    });
    $(".rating-raty").raty({
        readOnly: function () {
            return $(this).attr("data-readOnly")
        },
        path: function () {
            return $(this).attr('data-path')
        },
        half:true,
        score: function () {
            return $(this).attr('data-score')
        },
        hints:[2,4,6,8,10],
        click: function (score, evt) {
            alert('执行ajax');
            // var marked = $("#movie-marked").getAttribute('data-marked');
            var movie_id = $(this).attr("data-movie-id");
            var user_id = $(this).attr("data-user-id");
            alert('ID: ' + this.id + "\nscore: " + score*2 + "\nevent: " + evt);
            $.ajax({
                method: "POST",
                dataType: "json",
                data: {'rate': score*2, "user-id": user_id, "movie-id": movie_id},
                url: '/movie_info/stampVerify/',
                success: function (data) {
                    $(".rating-action-star").empty();
                    $(".rating-action-star").append(
                        ' <div id="rating-raty"' + ' class="rating-raty"\n' +
                        ' data-path="' + '/static/movie/images/img"' +
                        ' data-readOnly="true"' +
                        ' data-score="' + data.rate + '">\n' +
                        data.rate + '</div>')
                },
                error: function () {
                    alert('fail')
                }
            })
        }
    });

});
